import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:niuren_demo/model/cDynamicPage_model.dart';
import 'package:niuren_demo/view/dynamic_page/cDynamicItem.dart';
import 'package:niuren_demo/view/dynamic_page/jk_over_scroll_behavior.dart';

class cDynamicPage extends StatefulWidget {
  @override
  _cDynamicPageState createState() => _cDynamicPageState();
}

class _cDynamicPageState extends State<cDynamicPage> {
  List dataSource = [];
  @override
  void initState() {
    super.initState();
    loadAsset();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.edit),
      ),
      body: Container(
        color: Colors.white,
        padding: EdgeInsets.symmetric(horizontal: 12),
        child: ScrollConfiguration(
          behavior: JKOverScrollBehavior(), // 去除下拉水波纹效果
          child: ListView.builder(
            physics: NeverScrollableScrollPhysics(),
            itemBuilder: (context, index) {
              return cDynamicItem(dataModel: dataSource[index],);
            },
            itemCount: dataSource.length,
          ),
        ),
      ),
    );
  }

  loadAsset() async {
    var value = await rootBundle.loadString('assets/mocks/mock_dynamic_data.json');
    List jsonList = json.decode(value);
    jsonList.forEach((element) {
      dataSource.add(cDynamicItemModel.fromJson(element));
    });
    // dataSource.add(value)
    print(jsonList.toString());
    setState(() {
    });
  }
}
